/*******************************************************************************
 * Copyright (c) 2006 CEA List.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA List - initial API and implementation
 *******************************************************************************/
package com.cea.papyrus.diagram.activity.editpart;

import org.eclipse.draw2d.IFigure;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.ElementImport;
import org.eclipse.uml2.uml.SendObjectAction;

import com.cea.papyrus.core.editor.ModelManager;
import com.cea.papyrus.core.figures.IconFigure;
import com.cea.papyrus.diagram.activity.figure.ActionFigure;
import com.cea.papyrus.diagraminterchange2.di2.GraphNode;
import com.cea.papyrus.diagraminterchange2.di2.Uml1SemanticModelBridge;

/**
 * Controller of a SendObjectAction
 *
 * @author Gilles Cannenterre
 * @since 29 mars 07
 */
public class SendObjectActionEditPart extends ActionEditPart {

	public SendObjectActionEditPart(GraphNode graphNode,
			ModelManager modelManager) {
		super(graphNode, modelManager);
	}

	/* (non-Javadoc)
	 * @see com.cea.papyrus.core.common.editpart.GraphNodeWithSemanticEditPart#getUmlElement()
	 */
	@Override
	public SendObjectAction getUmlElement() {
		Element e = ((Uml1SemanticModelBridge)getGraphNode().getSemanticModel()).getElement();
		// Case of element import
		if(e instanceof ElementImport){
			return (SendObjectAction)((ElementImport) e).getImportedElement();
		}
		// This is a simple SendObjectAction
		return (SendObjectAction)e;
	}

	protected void refreshVisuals() {
		super.refreshVisuals();		
		IFigure fig = getFigure();

		// Classifier
		if (!(fig instanceof IconFigure)) {
			SendObjectAction currentAction = getUmlElement();
			String out="";
			if(currentAction.getRequest()!=null&& currentAction.getTarget()!=null){
				out="SendObject "+currentAction.getRequest().getName();
				out+=" to "+currentAction.getTarget().getName();
				((ActionFigure) fig).setName(out);
			}
			
		
			

			// qualifiedName
		}  
	}
}
